package com.ctgu.tengyun.service.role.impl;

import com.ctgu.tengyun.dao.mybatis.SysRoleMapper;
import com.ctgu.tengyun.domain.SysRole;
import com.ctgu.tengyun.domain.SysRoleExample;
import com.ctgu.tengyun.manager.UserRoleScheduleManager;
import com.ctgu.tengyun.service.role.SysRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by liaoweizhi on 2019/8/13.
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Resource
    private SysRoleMapper mapper;
    @Resource
    private UserRoleScheduleManager userRoleScheduleManager;

    @Override
    public int insertSelective(SysRole record) {
        return mapper.insertSelective(record);
    }

    @Override
    public List<SysRole> selectAll() {
        SysRoleExample example = new SysRoleExample();
        SysRoleExample.Criteria criteria = example.createCriteria();

        criteria.andIsValidEqualTo(1);

        return mapper.selectByExample(example);
    }

    @Override
    public SysRole selectByPrimaryKey(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int upsert(SysRole record) {
        int result = mapper.upsert(record);
        userRoleScheduleManager.fillData();
        return result;
    }
}
